<template>
  <div class="recommend">
    <swiper class="swiper" :options="swiperOptions">
      <swiper-slide v-for="item of data.recommend" :key="item.goodsId">
        <van-image :src="$resetUrl(item.image)"></van-image>
        <p class="recommend-comtent">
          {{ item.goodsName }}
        </p>
        <p class="recommend-comtent">
          ￥{{ toFixed(item.price) }}({{ toFixed(item.mallPrice) }})
        </p>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/swiper.min.css"; // node_modules\swiper\swiper.scss
export default {
  components: {
    Swiper,
    SwiperSlide,
  },
  props: {
    data: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      swiperOptions: {
        slidesPerView: 3,
        spaceBetween: 30,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        // Some Swiper option/callback...
      },
    };
  },
  methods: {
    toFixed(result) {
      if (typeof result !== "number") {
        result = Number(result);
      }
      return result.toFixed(2);
    },
  },
};
</script>

<style scoped>
.recommend .recommend-comtent {
  font-size: 24px;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis; 
}
</style>